const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var open = wx.getStorageSync('open');
    this.setData({
      platform:app.globalData.platform,    
      open:open,
       width:app.globalData.windowWidth,
      height:app.globalData.windowHeight,
      statusBarHeight:app.globalData.statusBarHeight,
      navHeight:app.globalData.navHeight,
      marginTop:app.globalData.navTitleTop,
      domain:app.globalData.domain
    })
  },
  goBack:function(){
    wx.navigateBack();
},
  select:function(e){
    var selected=this.data.selected;
    if(selected==false){
      selected=true;
    }else{
      selected=false;
    }
    this.setData({
      selected:selected
    })
  },
  getPhoneNumber:function (e) {
    let selected = this.data.selected;
    if(selected == 0){
        wx.showModal({
          title: '重要提示',
          content:'请阅读并同意隐私政策'
        })
        return
    }
    var open = wx.getStorageSync('open');
    console.log(e);

            wx.request({
                url:app.globalData.domain+'wechat/login/getPhone',
                data:{
                  code:e.detail.code,
                   id:open.id,
                   openid:open.openid
              
                },
                method:'GET',
                header:{
                    'content-type':'application/json'
                },
                success:function(res){
                  console.log(res)
                    //wx.setStorageSync('PhoneNumber',res.data.phone);
                    if(res.data.code==200){
                      open.mobile = res.data.phone;
                      wx.setStorageSync('open', open);
                      wx.showToast({
                        title: '登陆成功',
                        success:function(res){
                          wx.navigateBack();
                        }
                      })
                    }else{
                      wx.showToast({
                        title: '登陆失败'
                      })
                    } 
                    //console.log("手机号为");
                    //console.log(res);
                },
                fail:function(err){
                    console.log(err);
                }
            })
   
  },
  goto:function(e){
    console.log(e);
    var url=e.currentTarget.dataset.url;
    var index=e.currentTarget.dataset.index;
    var parent_id=wx.getStorageSync('parent_id');
    if(url=="#"){

    }else if(url=='phone'){
        wx.makePhoneCall({
          phoneNumber: '400-800-2177',
        })
    }else if(index=='index'){
        wx.reLaunch({
          url: url,
        })
    }else{
        wx.navigateTo({
          url: url,
        })
    }
    console.log(url);
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})